package mr.ali.videoapp.portal.controller;

import lombok.extern.slf4j.Slf4j;
import mr.ali.videoapp.portal.service.impl.WechatPhoneService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class PhoneController {

    @Autowired
    private WechatPhoneService wechatPhoneService;

    @GetMapping("/getSession")
    public JSONObject getVerify(@RequestParam("code") String code) {
        try {
            return wechatPhoneService.getVerifyInfo(code);
        } catch (Exception e) {
            log.error("获取用户信息失败", e);
            // 可以根据具体需求返回错误信息的 JSON 对象
            JSONObject errorResponse = new JSONObject();
            errorResponse.put("error", e.getMessage());
            return errorResponse;
        }
    }
}
